let fs = require('fs')

// Parse arguments
let i = 2;
while (i < process.argv.length) {
    let arg = process.argv[i]

    switch (arg) {
        // case '--version':
        // case '-v':
        //     manifest.version = process.argv[i + 1]
        //     i += 2
        //     break
        default:
            i++
            break
    }
}

/**
 * check ABIs
 */
let gradlePaths = [
        '../build/jsb-default/frameworks/runtime-src/proj.android-studio/gradle.properties',
    ],
    oAppAbis,
    newAppAbis

/**
 * 读取现有的 ABIs，并构建新的 ABIs
 */
fs.readFile(gradlePaths[0], (err, data) => {
    if (err) {
        console.log(err)
    } else {
        data = data.toString()
        oAppAbis = data.match(/[\n]PROP_APP_ABI=(\S*)/)[0].split(`:`)
        newAppAbis = [oAppAbis[0]]

        /**
         * 替换新的 ABIs
         */
        gradlePaths.forEach(gradlePath => {
            fs.readFile(gradlePath, (err, data) => {
                if (err) {
                    console.log(err)
                } else {
                    data = data.toString()
                    data = data.replace(oAppAbis.join(`:`), newAppAbis.join(`:`))
        
                    fs.writeFile(gradlePath, data, err => {
                        if (err) {
                            console.log(err)
                        }
                    })
                }
            })
        })
    }
})